//
//  WalletAddressCell.m
//  AppleMarket
//
//  Created by yangy on 13/11/2018.
//  Copyright © 2018 szgsy. All rights reserved.
//

#import "WalletAddressCell.h"

// model
#import "AddressModel.h"

@interface WalletAddressCell()
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *addressLabel;
@property (nonatomic, strong) UIView *blockView;
@end

@implementation WalletAddressCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        [self.contentView addSubview:self.blockView];
        [self.blockView addSubview:self.addressLabel];
        [self.blockView addSubview:self.nameLabel];
        
        [_blockView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_equalTo(UIEdgeInsetsMake(7.5, 15, 7.5, 15));
        }];
        
        [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.blockView.mas_left).offset(15);
            make.bottom.mas_equalTo(self.blockView.mas_centerY).offset(-5);
        }];
        
        [_addressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.blockView.mas_left).offset(15);
            make.top.mas_equalTo(self.blockView.mas_centerY).offset(5);
        }];
    }
    return self;
}

- (void) updateWithModel:(AddressModel*) model
{
    _nameLabel.text = model.Memo;
    _addressLabel.text = model.BlockAddr;
}

- (UIView *)blockView
{
    if(!_blockView){
        _blockView = [[UIView alloc] init];
        _blockView.backgroundColor = [UIColor whiteColor];
        _blockView.layer.cornerRadius = 2;
        _blockView.layer.shadowColor = [UIColor colorWithRed:13/255.0 green:76/255.0 blue:135/255.0 alpha:0.3].CGColor;
        _blockView.layer.shadowOffset = CGSizeMake(0, 2);
        _blockView.layer.shadowRadius = 3;
        _blockView.layer.shadowOpacity = 1;
    }
    return _blockView;
}

- (UILabel *)nameLabel
{
    if(!_nameLabel){
        _nameLabel = [UILabel cm_labelWithText:@"########" font:kFontBold(17) textColor:kColorWithHex(0x0E304C)];
    }
    return _nameLabel;
}

- (UILabel *)addressLabel
{
    if(!_addressLabel){
        _addressLabel = [UILabel cm_labelWithText:@"###########" font:kFont(15) textColor:kColorWithHex(0x0E304C)];
    }
    return _addressLabel;
}

@end
